package com.example.my.meila.view.adapter.beautyadapter;

import android.content.Context;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.my.meila.R;
import com.example.my.meila.entity.MakeUp;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

import static android.support.v7.widget.RecyclerView.ViewHolder;


/**
 * Created by My on 2016/11/1.
 */
public class MakeUpAdapter extends RecyclerView.Adapter<ViewHolder> {



    private Context context;
    private List<MakeUp.DataBean.VideosBean> data;
    private List<MakeUp.DataBean.FeedsBean> data2;
    public static final int TYPE_VIDEO = 0;
    public static final int TYPE_CONTENT = 1;

    public MakeUpAdapter(Context context, List<MakeUp.DataBean.VideosBean> data, List<MakeUp.DataBean.FeedsBean> data2) {
        this.context = context;
        this.data = data;
        this.data2 = data2;
    }


    @Override
    public int getItemCount() {
        return 2;
    }


    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        ViewHolder holder = null;
        if (viewType == 0) {
            holder = new VideoViewHolder(LayoutInflater.from(context).inflate(R.layout.item_beauty_makeupviedo, null));

        }
        if (viewType == 1) {
            holder = new ContextViewHolder(LayoutInflater.from(context).inflate(R.layout.item_beauty_makeupcontent, null));

        }


        return holder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        if (holder instanceof VideoViewHolder) {
          ((VideoViewHolder) holder).videoXrev.setLayoutManager(new LinearLayoutManager(context,LinearLayoutManager.VERTICAL,false));
                    ((VideoViewHolder) holder).videoXrev.setAdapter(new MakeUpChildAdapter(context,data));

        }if(holder instanceof ContextViewHolder){
            ((ContextViewHolder) holder).contentXrev.setLayoutManager(new LinearLayoutManager(context,LinearLayoutManager.VERTICAL,false));
            ((ContextViewHolder) holder).contentXrev.setAdapter(new MakeUpChildConAdapter(context,data2));

        }


    }

    @Override
    public int getItemViewType(int position) {
        int item = 0;
        if (position == 0) {
            item = TYPE_VIDEO;
        }
        if (position == 1) {
            item = TYPE_CONTENT;
        }
        return item;
    }

    class VideoViewHolder extends ViewHolder {
        @BindView(R.id.video_xrev)
        RecyclerView videoXrev;

        public VideoViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

    class ContextViewHolder extends ViewHolder {
        @BindView(R.id.content_xrev)
        RecyclerView contentXrev;
        public ContextViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this,itemView);
        }
    }

}
